﻿var Normal_SupportRecordList;
var Normal_SupportRecordStore;
// 功能模块grid展示
Normal_SupportRecordList = function() {
    var url = "/manager/Normal_SupportRecord/List";
    var sm = Ext.create('Ext.selection.CheckboxModel');

    //grid 填充
    Ext.define('Normal_SupportRecordGridModel', {
        extend: 'Ext.data.Model',
        fields: [
            { name: "Ip", type:"string"},
            { name: "AddDate", type:"datetime"},
            { name: "ModuleType", type:"string"},
            { name: "Id", type:"string"}
            ]
    });

    //grid获取 json数组
    Normal_SupportRecordStore = Ext.create('Ext.data.Store', {
        pageSize: CMN.pageSize,
        model: 'Normal_SupportRecordGridModel',
        buffered: false,  //是否动态加载
        proxy: {
            actionMethods: 'post',
            type: 'ajax',
            url: url,
            reader: {
                type: 'json',
                root: 'root',
                totalProperty: 'totalPorperty'
            }
        },
        sorters: [{
            property: 'Id',
            direction: 'DESC'
}]
        });

        //分页设置
        var pagingBar = Ext.create('Ext.PagingToolbar', {
            displayInfo: true, emptyMsg: "没有数据显示", displayMsg: "显示从{0}条数据到{1}条数据，共{2}条数据",
            store: Normal_SupportRecordStore,
            pageSize: CMN.pageSize,
            //显示右下角信息
            prevText: "上一页",
            nextText: "下一页",
            refreshText: "刷新",
            lastText: "最后页",
            firstText: "第一页",
            beforePageText: "当前页",
            afterPageText: "共{0}页"
        });

        //删除选中行信息
        DeleteNormal_SupportRecordFn = function() {
            var row = Ext.getCmp("Normal_SupportRecordPanel").getSelectionModel().getSelection();
            if (row.length == 0) {
                Ext.Msg.alert("提示信息", "请您至少选择一个!");
            }
            else if (row.length > 1) {
                var idList = "";
                for (var i = 0; i < row.length; i++) {
                    if (i == 0) {
                        idList = row[0].data.Id;
                    }
                    else {
                        idList = idList +"_" + row[i].data.Id;
                    }
                }
                //Ext.Msg.alert("提示信息", "对不起只能选择一个!");
                Ext.Msg.confirm("提 示!", "您确定要删除" + idList + "吗?", function(btn) {
                    if (btn == "yes") {
                        Ext.Ajax.request({
                            url: "/manager/Normal_SupportRecord/DeleteList/" + idList,
                            method: "get",
                            success: function(d) {
                                //成功后
                                var action = Ext.JSON.decode(d.responseText);
                                //alert(action.success);
                                var flag = action.success;
                                if (flag == "true") {
                                    Normal_SupportRecordStore.loadPage(1);
                                    Ext.MessageBox.alert("恭喜", "删除成功!");
                                }
                                else {
                                    var message = action.result.message;
                                    if (message) {
                                        Ext.MessageBox.alert("删除失败!", message);
                                    }
                                    else {
                                        Ext.MessageBox.alert("提示!", "删除失败!");
                                    }
                                }
                            },
                            failure: function(form, action) {
                                Ext.MessageBox.alert("提示!", "修改失败!");
                            }
                        })
                    }
                    else {

                    }
                })
            }
            else if (row.length == 1) {
                Ext.Msg.confirm("提 示!", "您确定要删除" + row[0].data.Id + "吗?", function(btn) {
                    if (btn == "yes") {
                        Ext.Ajax.request({
                            url: "/manager/Normal_SupportRecord/Delete/" + row[0].data.Id,
                            method: "POST",
                            success: function(d) {
                                //成功后
                                var action = Ext.JSON.decode(d.responseText);
                                //alert(action.success);
                                var flag = action.success;
                                if (flag == "true") {
                                    Normal_SupportRecordStore.loadPage(1);
                                    Ext.MessageBox.alert("恭喜", "删除成功!");
                                }
                                else {
                                    var message = action.result.message;
                                    if (message) {
                                        Ext.MessageBox.alert("删除失败!", message);
                                    }
                                    else {
                                        Ext.MessageBox.alert("提示!", "删除失败!");
                                    }
                                }
                            },
                            failure: function(form, action) {
                                Ext.MessageBox.alert("提示!", "修改失败!");
                            }
                        })
                    }
                    else {

                    }
                })
            }
        }


        //修改选中行信息
        EditNormal_SupportRecordFn = function() {
            var row = Ext.getCmp("Normal_SupportRecordPanel").getSelectionModel().getSelection();
            if (row.length == 0) {
                Ext.Msg.alert("提示信息", "您没有选中任何行!");
            }
            else if (row.length > 1) {
                Ext.Msg.alert("提示信息", "对不起只能选择一个!");
            } else if (row.length == 1) {
                EditNormal_SupportRecord(row[0].data.Id);
            }

        }

        //新增信息
        SaveNormal_SupportRecordFn = function() {
            InsertNormal_SupportRecord();
        }

        //grid配置
        var grid = Ext.create('Ext.grid.Panel', {
            id: "Normal_SupportRecordPanel",
            renderTo: "Normal_SupportRecordGrid",
            layout: "fit",
            alias: 'widget.methodPanel',
            columnLines: true,
            loadMask: true,
            frame: true,
            border: false,
            selModel: sm,   //选择框
            autoScroll: true,
            store: Normal_SupportRecordStore,
            ds: Normal_SupportRecordStore,
            sm: sm,
            columnLines: true,
            //cm: cm2,
            viewConfig: {
                stripeRows: true,
                trackOver: true,
                emptyText: '<div style="color:#999;margin:5px;">当前没有记录显示<div>'
            },
            stripeRows: true,
            listeners: {
                "itemdblclick": function(g, rowIndex, e) {
                    EditNormal_SupportRecordFn();
                }
            },
            bbar: pagingBar,
            tbar: [            		 //工具条设置
            		 {
            		 text: "新增",
            		 tooltip: "新增",
            		 iconCls: "addicon",
            		 handler: SaveNormal_SupportRecordFn
           }, "", "-", "", {
               text: "编辑",
               tooltip: "编辑",
               iconCls: "editicon",
               handler: EditNormal_SupportRecordFn
           }, "", "-", "", {
               text: "删除",
               tooltip: "删除",
               iconCls: "deleteicon",
               handler: DeleteNormal_SupportRecordFn
           }, "-"],
            columns: [
               Ext.create('Ext.grid.RowNumberer'),

                { header: "IP地址", dataIndex: "Ip", width: 80, sortable: true },

                { header: "添加时间", dataIndex: "AddDate", width: 80, sortable: true },

                { header: "文章类型", dataIndex: "ModuleType", width: 80, sortable: true },

                { header: "", dataIndex: "Id", width: 80, sortable: true },
                { header: "删除", dataIndex: "Id", renderer: function(value) { return "<a href='javascript:void(0);' title='删除' onclick='DeleteNormal_SupportRecordFn()'class='deleteBtn' >&nbsp;&nbsp;&nbsp;</a>" }, width: 40 }    
            ]
        });
        Normal_SupportRecordStore.loadPage(1);
       
    }
    Normal_SupportRecordList();
